package igz.fleaxy.air
{
	import flash.display.Screen;
	import flash.geom.Rectangle;
	
	public class ScreenManager
	{
		
		private var _ScreensArrays:Array;
		private var _PrincipalScreen:Rectangle;
		private var _SecondaryScreen:Rectangle;		
		private var _PrincipalStage:Rectangle;		
		
		public function ScreenManager() 
		{
			_ScreensArrays = Screen.screens;
			_PrincipalStage = new Rectangle(0, 0, 0 , 0);
			if (Screen.screens.length > 1)
			{
				_PrincipalScreen = Screen.mainScreen.bounds;
				_PrincipalStage = _PrincipalScreen;
			}
			else
			{
				var n:Number = 0;
				var minx:Number = 0;
				var miny:Number = 0;
				var width:Number = 0;
				var height:Number = 0;
				var currentScreen : Screen;
				for (n = 0; n < Screen.screens.length; n++)
				{
					if (width == 0)
					{
						width = Screen.screens[n].bounds.width;
						height = Screen.screens[n].bounds.height;
					}else
					{
						if (Screen.screens[n].bounds.x!=0)
						{
							width = width + Screen.screens[n].bounds.width;
							height = Math.max(height, Screen.screens[n].bounds.height);
						}
						if (Screen.screens[n].bounds.y!=0)
						{
							height = height + Screen.screens[n].bounds.height;
							width = Math.max(width, Screen.screens[n].bounds.width);
						}						
					}
					
					minx = Math.min(minx, Screen.screens[n].bounds.x);
					miny = Math.min(minx, Screen.screens[n].bounds.y);
					if ( _CompareBounds(Screen.mainScreen.bounds, Screen.screens[n].bounds) )
					{
						_PrincipalScreen = Screen.screens[n].bounds;
					}else
					{
						_SecondaryScreen = Screen.screens[n].bounds;
					}
				}
				_PrincipalStage = new Rectangle(minx, miny, width, height);
			}
		}
		
		private function _CompareBounds ( p_one:Rectangle, p_two:Rectangle ) : Boolean {
			return (p_one.x == p_two.x) && (p_one.y == p_two.y) 
				&& (p_one.width == p_two.width) && (p_one.height == p_two.height)
				;
		}
		
		public function $GetScreens():Array
		{
			return _ScreensArrays;
		}
		
		public function $GetPrincipalScreen():Rectangle
		{
			return Screen.mainScreen.bounds;
		}

		public function $GetSecondaryScreen():Rectangle
		{
			return _SecondaryScreen;
		}		

		
		public function $GetTotalStage():Rectangle
		{
			
		}		
		
		
	}

}